# Construct 'agModeling' object or its extensions which are the basic 
#        object recongized by most of functions in this fold 
# 
# @population: an object of 'population' class
# @covariances: a list of covariance 'im' objects
# @select: logical, define whether covariables should be selected in the following steps.
# @pvalue: logical, define whether pvalue of regression parameters and cluster relavent 
#                 parameters should be calcualted
# @models: a list model names
#
# Author: guochun
###############################################################################


constructModel=function(population, covariances, select, pvalue, models,nu=1/2){
	modelObjects=list()
	
	formu=formu(names(covariances))
	for (m in models){
		if(m=="Poisson"){
			mo=new("poissonM",population=population,covr=covariances,formu=formu,
					select=select,pvalue=pvalue)
		}else if(m=="LGCP"){
			mo=new("logGaussianM",population=population,covr=covariances,formu=formu,
					select=select,pvalue=pvalue)
		}else if (m=="Thomas"){
			mo=new("thomasM",population=population,covr=covariances,formu=formu,
					select=select,pvalue=pvalue)
		}else if (m=="Matern"){
			mo=new("maternM",population=population,covr=covariances,formu=formu,
					select=select,pvalue=pvalue,nu=nu)
		}
		attr(mo,"models")=m
		modelObjects=c(modelObjects,mo)
	}
	if(length(models)==1){
		return(modelObjects[[1]])
	}else
	    return(modelObjects)
}
